﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 人员BLL
    /// </summary>
    public class HREmpl
    {
        /// <summary>
        /// 人员DAL
        /// </summary>
        private readonly DAL.HREmpl dal = new DAL.HREmpl();
        /// <summary>
        /// 构造方法
        /// </summary>
        public HREmpl()
        { }

                /// <summary>
        /// 是否是正级
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool isFPositionProp(string fEmplNo)
        {
            return dal.isFPositionProp(fEmplNo);
        }
        /// <summary>
        /// 是否是正级(副级)
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool IsMainOrSub(string emplNo)
        {
            return dal.IsMainOrSub(emplNo);
        }
                /// <summary>
        /// 获取人员名称
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetEmpNameAndDept(string entityNo, string empNo)
        {
            return dal.GetEmpNameAndDept(entityNo, empNo);
        }
        public string GetEmpNameAndDeptFIsAllowLookFtp(string entityNo, string empNo)
        {
            return dal.GetEmpNameAndDeptFIsAllowLookFtp(entityNo, empNo);
        }

        public List<Model.HREmpl> GetEmplListFIsAllowLookFtp(string entityNo)
        {
            return DataTableToListEmpl(dal.GetEmplListFIsAllowLookFtp(entityNo).Tables[0]);
        }
        /// <summary>
        /// 是否存在该记录
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool Exists(string fEntityNo, string fEmplNo)
        {
            return dal.Exists(fEntityNo, fEmplNo);
        }


        /// <summary>
        /// 删除人员和人员岗位数据 事务模式
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <param name="entityNo">组织机构编号</param>
        public void DelEmlAndPosition(string empNo, string entityNo)
        {
            dal.DelEmlAndPosition(empNo, entityNo);
        }

        /// <summary>
        /// 获取人员名称
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetEmpName(string entityNo, string empNo)
        {
            return dal.GetEmpName(entityNo, empNo);
        }

        /// <summary>
        /// 批量删除人员数据 事务模式
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNoArray">人员列表</param>
        /// <param name="entityNo">组织机构编号</param>
        public void DelManyEmlAndPosition(string[] empNoArray, string entityNo)
        {
            dal.DelManyEmlAndPosition(empNoArray, entityNo);
        }



        /// <summary>
        /// 判断当前选择的岗位是否有正级岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="emplNo">人员编号</param>
        /// <param name="deptNos">部门编号</param>
        /// <param name="positionNos">岗位编号</param>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>是否正级岗位</returns>
        public int GetIsMainPositionCount(string emplNo, string deptNos, string positionNos, string entityNo)
        {
            return dal.GetIsMainPositionCount(emplNo, deptNos, positionNos, entityNo);
        }

        /// <summary>
        /// 获取图片二进制流
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>2进制图片数据</returns>
        public byte[] GetPhoto(string empNo, string entityNo)
        {
            return dal.GetPhoto(empNo, entityNo);
        }
        

        /// <summary>
        /// 保存用户和用户岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <param name="empPositionList">岗位信息</param>
        public void AddEmplAndPosition(Model.HREmpl model, List<Model.HREmplPosition> empPositionList)
        {
            dal.AddEmplAndPosition(model, empPositionList);
        }


        /// <summary>
        /// 更新用户和用户岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <param name="empPositionList">岗位列表</param>
        public void UpdateEmplAndPosition(Model.HREmpl model, List<Model.HREmplPosition> empPositionList)
        {
            dal.UpdateEmplAndPosition(model, empPositionList);
        }

        /// <summary>
        /// 获得一个实体对象
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fEmplNo">用户编号</param>
        /// <returns>用户信息</returns>
        public Model.HREmpl GetModel(string fEntityNo, string fEmplNo)
        {

            return dal.GetModel(fEntityNo, fEmplNo);
        }

        /// <summary>
        /// 获取该部门所有人员
        /// <creator>wangl</creator>
        /// <date>2013-10-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <returns></returns>
        public List<Model.HREmpl> GetDeptEmplList(string entityNo, string deptNo)
        {
            DataSet ds = dal.GetDeptEmplList(entityNo, deptNo);
            return DataTableToListEmpl(ds.Tables[0]);
        }
        /// <summary>
        /// 人员排序
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="emplNos">员工编号集合</param>
        /// <param name="entityNo">公司编号</param>
        public void SeqEmplTop(string[] emplNos, string entityNo)
        {
            dal.SeqEmplTop(emplNos, entityNo);
        }
        /// <summary>
        /// 获取人员列表显示数据字段 部分字段 FEmplNo,FEmpName,FOfficeTel,FMobile,FSex,FDutyNo
        /// </summary>
        /// <param name="dt">需转换数据</param>
        /// <returns>转换后数据</returns>
        public List<Model.HREmpl> DataTableToListEmpl(DataTable dt)
        {
            List<Model.HREmpl> modelList = new List<Model.HREmpl>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.HREmpl model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.HREmpl();
                    if (dt.Rows[n]["FEmplNo"] != null && dt.Rows[n]["FEmplNo"].ToString() != "")
                    {
                        model.FEmplNo = dt.Rows[n]["FEmplNo"].ToString();
                    }
                    if (dt.Rows[n]["FEmpName"] != null && dt.Rows[n]["FEmpName"].ToString() != "")
                    {
                        model.FEmpName = dt.Rows[n]["FEmpName"].ToString();
                    }
                    if (dt.Rows[n]["FOfficeTel"] != null && dt.Rows[n]["FOfficeTel"].ToString() != "")
                    {
                        model.FOfficeTel = dt.Rows[n]["FOfficeTel"].ToString();
                    }
                    if (dt.Rows[n]["FMobile"] != null && dt.Rows[n]["FMobile"].ToString() != "")
                    {
                        model.FMobile = dt.Rows[n]["FMobile"].ToString();
                    }
                    if (dt.Rows[n]["FSex"] != null && dt.Rows[n]["FSex"].ToString() != "")
                    {
                        model.FSex = dt.Rows[n]["FSex"].ToString();
                    }
                    if (dt.Rows[n]["FDutyNo"] != null && dt.Rows[n]["FDutyNo"].ToString() != "")
                    {
                        model.FDutyNo = dt.Rows[n]["FDutyNo"].ToString();
                    }
                    if (dt.Columns.Contains("FLoginIPAddress"))
                    {
                        if (dt.Rows[n]["FLoginIPAddress"] != null)
                        {
                            model.FLoginIPAddress = dt.Rows[n]["FLoginIPAddress"].ToString();
                        }
                    }
                    if (dt.Columns.Contains("FIsAllowLookFtp"))
                    {
                        if (dt.Rows[n]["FIsAllowLookFtp"]!=null)
                        {
                            model.FIsAllowLookFtp = dt.Rows[n]["FIsAllowLookFtp"].ToString();
                        }
                    }

                    
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 根据员工编号从V_HREmpl中获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-18</date>
        /// </summary>
        /// <param name="emplNo">员工</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetEmplFromViewByEmplNo(string emplNo, string entityNo)
        {
            return dal.GetEmplFromViewByEmplNo(emplNo, entityNo);
        }
        /// <summary>
        /// 更新用户基本信息
        /// <creator>wangl</creator>
        /// <date>2013-10-19</date>
        /// </summary>
        /// <param name="hrEmplModel"></param>
        public void UpdateEmplBaseInfo(Model.HREmpl hrEmplModel)
        {
            dal.UpdateEmplBaseInfo(hrEmplModel);
        }
        /// <summary>
        /// 获取是否需要考勤
        /// <creator>chenly(wangl引用)</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetIsAttendance(string entityNo, string empNo)
        {
            return dal.GetIsAttendance(entityNo, empNo);
        }
        /// <summary>
        /// 获取考勤IP
        /// <creator>chenly(wangl引用)</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetAttendanceIpAddress(string entityNo, string empNo)
        {
            return dal.GetAttendanceIpAddress(entityNo, empNo);
        }
        ///// <summary>
        ///// 根据公司编号获取员工表
        ///// <creator>sunlj</creator>
        ///// <date>2013-7-18</date>
        ///// </summary>
        ///// <param name="FEntityNo">公司编号</param>
        ///// <returns>返回员工表数据</returns>
        //public List<Model.HREmpl> GetModelListByEntityNo(string FEntityNo)
        //{
        //    return dal.GetModelListByEntityNo(FEntityNo);
        //}


     

        /// <summary>
        /// 获取该部门所有人员
        /// <creator>sunlj</creator>
        /// <date>2013-10-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <returns></returns>
        public List<Model.HREmpl> GetEmplList(string entityNo)
        {
            DataSet ds = dal.GetEmplList(entityNo);
            return DataTableToListEmpl(ds.Tables[0]);
        }

        public void UpdataEmplFIsAllowLookFtp(List<Model.HREmpl> emplModelList, string EntityNo)
        {
            dal.UpdataEmplFIsAllowLookFtp(emplModelList, EntityNo);
        }
    }
}
